package o;

import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutInfo.Builder;
import android.content.pm.ShortcutManager;
import android.net.Uri;
import android.os.Build.VERSION;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.huawei.appgallery.shortcutmanager.impl.RequestResultReceiver;
import com.huawei.hmf.annotation.ApiDefine;
import java.io.Closeable;
import java.net.URISyntaxException;
import java.util.List;
import o.cyf.d;

@ApiDefine(uri = cyf.class)
public class cyc implements cyf {
    public boolean ˋ(@NonNull Context context, @NonNull String str) {
        return cyl.ˋ(context).ˊ(str);
    }

    @TargetApi(26)
    public boolean ˊ(@NonNull Context context) {
        if (VERSION.SDK_INT < 26) {
            return ˎ(context);
        }
        ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(ShortcutManager.class);
        if (shortcutManager == null) {
            return false;
        }
        return shortcutManager.isRequestPinShortcutSupported();
    }

    boolean ˎ(@NonNull Context context) {
        if (cyh.ˋ(context, "com.android.launcher.permission.INSTALL_SHORTCUT") != 0) {
            return false;
        }
        PackageManager packageManager = context.getPackageManager();
        if (packageManager == null) {
            return false;
        }
        List<ResolveInfo> queryBroadcastReceivers = packageManager.queryBroadcastReceivers(new Intent("com.android.launcher.action.INSTALL_SHORTCUT"), 0);
        if (queryBroadcastReceivers == null) {
            return false;
        }
        for (ResolveInfo resolveInfo : queryBroadcastReceivers) {
            CharSequence charSequence = resolveInfo.activityInfo.permission;
            if (!TextUtils.isEmpty(charSequence)) {
                if ("com.android.launcher.permission.INSTALL_SHORTCUT".equals(charSequence)) {
                }
            }
            return true;
        }
        return false;
    }

    @TargetApi(26)
    public boolean ˏ(@NonNull Context context, @NonNull cxx o_cxx, @Nullable d dVar) {
        Intent ˎ = o_cxx.ˎ();
        if (VERSION.SDK_INT >= 26) {
            ˎ.putExtra("simpleui_mode", cyh.ˎ(context));
            ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(ShortcutManager.class);
            if (shortcutManager == null) {
                return false;
            }
            return shortcutManager.requestPinShortcut(ˎ(context, o_cxx), RequestResultReceiver.getRequestPinShortcutResultIntent(context, o_cxx.ॱ(), dVar).getIntentSender());
        }
        ˎ.putExtra("shortcut_id", o_cxx.ॱ());
        if (!ˎ(context)) {
            return false;
        }
        context.sendOrderedBroadcast(ˋ(context, o_cxx), null, ˏ(o_cxx, dVar), null, -1, null, null);
        return true;
    }

    static BroadcastReceiver ˏ(final cxx o_cxx, final d dVar) {
        return new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                if (dVar != null) {
                    dVar.ˊ(o_cxx);
                }
            }
        };
    }

    @RequiresApi(26)
    @TargetApi(26)
    static ShortcutInfo ˎ(@NonNull Context context, cxx o_cxx) {
        if (context == null) {
            throw new NullPointerException("context must not be null.");
        }
        Builder builder = new Builder(context, o_cxx.ॱ());
        builder.setShortLabel(o_cxx.ˏ());
        if (o_cxx.ˊ() != null) {
            builder.setIcon(o_cxx.ˊ().ˋ());
        }
        builder.setIntent(o_cxx.ˎ());
        if (o_cxx.ˋ() != null) {
            builder.setActivity(o_cxx.ˋ());
        }
        return builder.build();
    }

    static Intent ˋ(Context context, cxx o_cxx) {
        Intent putExtra = new Intent("com.android.launcher.action.INSTALL_SHORTCUT").putExtra("android.intent.extra.shortcut.NAME", o_cxx.ˏ()).putExtra("android.intent.extra.shortcut.INTENT", o_cxx.ˎ()).putExtra("duplicate", false);
        if (o_cxx.ˊ() != null) {
            o_cxx.ˊ().ˎ(putExtra);
        }
        return putExtra;
    }

    public boolean ˏ(@NonNull Context context) {
        if (VERSION.SDK_INT >= 26) {
            return false;
        }
        if (cyh.ˋ(context, "com.android.launcher.permission.UNINSTALL_SHORTCUT") != 0) {
            return false;
        }
        for (ResolveInfo resolveInfo : context.getPackageManager().queryBroadcastReceivers(new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT"), 0)) {
            CharSequence charSequence = resolveInfo.activityInfo.permission;
            if (!TextUtils.isEmpty(charSequence)) {
                if ("com.android.launcher.permission.UNINSTALL_SHORTCUT".equals(charSequence)) {
                }
            }
            return true;
        }
        return false;
    }

    public boolean ˊ(@NonNull Context context, @NonNull cxx o_cxx) {
        if (VERSION.SDK_INT >= 26 || !ˏ(context)) {
            return false;
        }
        context.sendBroadcast(new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT").putExtra("android.intent.extra.shortcut.NAME", o_cxx.ˏ()).putExtra("android.intent.extra.shortcut.INTENT", o_cxx.ˎ()));
        cyl.ˋ(context).ˊ(o_cxx.ॱ(), false);
        return true;
    }

    @TargetApi(26)
    public boolean ˊ(@NonNull Context context, @NonNull List<cxx> list) {
        list.clear();
        String ॱ = cyh.ॱ(context);
        if (TextUtils.isEmpty(ॱ)) {
            return false;
        }
        String str;
        int ˎ = cyh.ˎ(context);
        if (ˎ == 1) {
            str = "content://" + ॱ + ".settings/favorites?notify=true";
        } else {
            str = "content://" + ॱ + ".settings/drawer_favorites?notify=true";
        }
        if (VERSION.SDK_INT >= 26) {
            ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(ShortcutManager.class);
            if (shortcutManager == null) {
                return false;
            }
            for (ShortcutInfo shortcutInfo : shortcutManager.getPinnedShortcuts()) {
                if (ˎ == 4) {
                    list.add(ˊ(shortcutInfo));
                } else if (ˋ(shortcutInfo, 4) == 1) {
                    list.add(ˊ(shortcutInfo));
                }
            }
        }
        ˋ(context, list, str);
        return true;
    }

    @RequiresApi(26)
    @TargetApi(26)
    static int ˋ(ShortcutInfo shortcutInfo, int i) {
        return shortcutInfo.getIntent() == null ? i : cyh.ˏ(shortcutInfo.getIntent(), "simpleui_mode", i);
    }

    static boolean ˋ(Context context, List<cxx> list, String str) {
        Object e;
        Throwable th;
        Closeable query;
        try {
            query = context.getContentResolver().query(Uri.parse(str), new String[]{"title", "intent"}, null, null, null);
            if (query != null) {
                try {
                    int columnIndex = query.getColumnIndex("title");
                    int columnIndex2 = query.getColumnIndex("intent");
                    while (query.moveToNext()) {
                        String string = query.getString(columnIndex);
                        String string2 = query.getString(columnIndex2);
                        if (!(TextUtils.isEmpty(string) || TextUtils.isEmpty(string2))) {
                            Intent ˏ = ˏ(string2);
                            if (ˏ != null) {
                                list.add(ˋ(string, ˏ));
                            }
                        }
                    }
                    cyh.ˎ(query);
                    return true;
                } catch (Exception e2) {
                    e = e2;
                    try {
                        cyk.ˏ.ˏ("HwShortcutManager", "Exception when getting the shortcut list, exception: " + e);
                        cyh.ˎ(query);
                        return false;
                    } catch (Throwable th2) {
                        th = th2;
                        cyh.ˎ(query);
                        throw th;
                    }
                }
            }
            cyh.ˎ(query);
            return false;
        } catch (Exception e3) {
            e = e3;
            query = null;
            cyk.ˏ.ˏ("HwShortcutManager", "Exception when getting the shortcut list, exception: " + e);
            cyh.ˎ(query);
            return false;
        } catch (Throwable th3) {
            th = th3;
            query = null;
            cyh.ˎ(query);
            throw th;
        }
    }

    static Intent ˏ(String str) {
        Intent intent = null;
        if (str != null) {
            try {
                intent = Intent.parseUri(str, 0);
            } catch (URISyntaxException e) {
            }
        }
        return intent;
    }

    @RequiresApi(26)
    @TargetApi(26)
    static cxx ˊ(ShortcutInfo shortcutInfo) {
        CharSequence shortLabel = shortcutInfo.getShortLabel();
        if (TextUtils.isEmpty(shortLabel)) {
            shortLabel = "[empty-title]";
        }
        String id = shortcutInfo.getId();
        if (TextUtils.isEmpty(id)) {
            id = shortLabel.toString();
        }
        return new cxx.d(id).ˎ(shortLabel.toString()).ˊ(shortcutInfo.getIntent()).ॱ(shortcutInfo.getActivity()).ˊ();
    }

    static cxx ˋ(String str, Intent intent) {
        String ˎ = cyh.ˎ(intent, "shortcut_id");
        if (TextUtils.isEmpty(ˎ)) {
            ˎ = str;
        }
        return new cxx.d(ˎ).ˎ(str).ˊ(intent).ॱ(intent.getComponent()).ˊ();
    }
}
